package com.hingstd.lastwork.controllers;

import com.hingstd.lastwork.dao.WarnRepository;
import com.hingstd.lastwork.entities.Article;
import com.hingstd.lastwork.entities.Warn;
import com.hingstd.lastwork.services.WarnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("warns")
public class WarnController {

    @Autowired
    WarnService warnService;


    @GetMapping("/new")
    public String displayWarnForm(Model model){

        Warn aWarn = new Warn();
        model.addAttribute("warn", aWarn);
        return "new-warn";
    }

    @PostMapping("/save")
    public String createWarn(Model model, Warn warn){
        //处理保存数据库
        warnService.save(warn);

        return "redirect:/warns/new";
    }
}
